﻿using S_Gridding.Domains.BasicData;
using S_Gridding.Domains.FoundGridding;
using SqlSugar;

namespace S_Gridding.Infrastructure
{
    /// <summary>
    /// 注入上下文类  相当于DbContext
    /// </summary>
    public class SqlSugarDbContext
    {
        /// <summary>
        /// 注入上下文类  相当于DbContext
        /// </summary>
        private readonly ISqlSugarClient _db;

        public SqlSugarDbContext(ISqlSugarClient db)
        {
            _db = db;
        }


        /// <summary>
        /// 迁移方法
        /// </summary>
        public void CreateDbContext()
        {
            //没有数据库则创建
            _db.DbMaintenance.CreateDatabase();
            //以codefirst的模式字符串长度为50的备份表
            _db.CodeFirst.SetStringDefaultLength(50).BackupTable().InitTables(new Type[]
            {
                typeof(MeshTypeInfo),//括号里面写要迁移的表    网络类型管理表
                typeof(AssemTypeInfo),//部件类型表

                //网格管理
                typeof(Gridding),
                typeof(Cellgrid),
                typeof(Responsibilitygrid),
                typeof(Teamgrid),

            });
        }

    }
}
